package avicit.bdp.oss.dto;

import avicit.bdp.common.base.BaseDTO;
import avicit.platform6.core.annotation.log.FieldRemark;
import avicit.platform6.core.annotation.log.Id;
import avicit.platform6.core.annotation.log.LogField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2020-11-12
 * @类说明：BucketAuthDto
 * @修改记录：
 * @注意事项：
 * @主要功能：Bucket中授权信息，作用于Object
 */
@ApiModel(value = "BucketAuthDto", description = "bdp_oss_bucket_auth")
@Table(name = "bdp_oss_bucket_auth")
public class BucketAuthDto extends BaseDTO {
    /**
     * 主键
     */
    @Id
    @LogField
    @ApiModelProperty(value = "主键")
    @FieldRemark(column = "id", field = "id", name = "id")
    @javax.persistence.Id
    @Column(name = "id")
    private String id;

    /**
     * 桶ID
     */
    @LogField
    @ApiModelProperty(value = "桶名称")
    @FieldRemark(column = "bucket_name", field = "bucket_name", name = "桶名称")
    @Column(name = "bucket_name")
    private String bucketName;

    /**
     * 对象ID
     */
    @LogField
    @ApiModelProperty(value = "对象ID")
    @FieldRemark(column = "object_id", field = "object_id", name = "对象ID")
    @Column(name = "object_id")
    private String objectId;

    /**
     * 策略模式
     */
    @LogField
    @ApiModelProperty(value = "策略")
    @FieldRemark(column = "strategy", field = "strategy", name = "策略")
    @Column(name = "strategy")
    private String strategy;

    /**
     * 授权用户
     */
    @LogField
    @ApiModelProperty(value = "授权用户，多个用户使用英文逗号隔开")
    @FieldRemark(column = "auth_user", field = "auth_user", name = "授权用户")
    @Column(name = "auth_user")
    private String authUser;

    /**
     * 资源
     */
    @LogField
    @ApiModelProperty(value = "资源")
    @FieldRemark(column = "resource", field = "resource", name = "资源")
    @Column(name = "resource")
    private String resource;

    /**
     * 用户名称，根据userId转换而来，提供给VUE前端
     */
    @ApiModelProperty(value = "用户名称")
    @Transient
    private String userName;

    /**
     * 无参构造函数，mybatis使用
     */
    public BucketAuthDto() {
    }

    public BucketAuthDto(String id, String bucketName, String objectId, String strategy,
                         String authUser, String resource, String userName) {
        this.id = id;
        this.bucketName = bucketName;
        this.objectId = objectId;
        this.strategy = strategy;
        this.authUser = authUser;
        this.resource = resource;
        this.userName = userName;
    }

    public String getId() {
        return id;
    }

    public String getBucketName() {
        return bucketName;
    }

    public String getObjectId() {
        return objectId;
    }

    public String getStrategy() {
        return strategy;
    }

    public String getAuthUser() {
        return authUser;
    }

    public String getResource() {
        return resource;
    }

    public String getUserName() {
        return userName;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    public void setObjectId(String objectId) {
        this.objectId = objectId;
    }

    public void setStrategy(String strategy) {
        this.strategy = strategy;
    }

    public void setAuthUser(String authUser) {
        this.authUser = authUser;
    }

    public void setResource(String resource) {
        this.resource = resource;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Override
    public String getLogFormName() {
        if (StringUtils.isEmpty(super.logFormName)) {
            return "授权信息管理";
        } else {
            return super.logFormName;
        }
    }

    @Override
    public String getLogTitle() {
        if (StringUtils.isEmpty(super.logTitle)) {
            return "授权信息";
        } else {
            return super.logTitle;
        }
    }

    public static BucketAuthDto.Builder builder() {
        return new BucketAuthDto.Builder();
    }

    public static final class Builder {
        String id;
        String bucketName;
        String objectId;
        String strategy;
        String authUser;
        String resource;
        String userName;

        public Builder() {
        }

        public BucketAuthDto.Builder id(String id) {
            this.id = id;
            return this;
        }

        public BucketAuthDto.Builder bucketName(String bucketName) {
            this.bucketName = bucketName;
            return this;
        }

        public BucketAuthDto.Builder objectId(String objectId) {
            this.objectId = objectId;
            return this;
        }

        public BucketAuthDto.Builder strategy(String strategy) {
            this.strategy = strategy;
            return this;
        }

        public BucketAuthDto.Builder authUser(String authUser) {
            this.authUser = authUser;
            return this;
        }

        public BucketAuthDto.Builder resource(String resource) {
            this.resource = resource;
            return this;
        }

        public BucketAuthDto.Builder userName(String userName) {
            this.userName = userName;
            return this;
        }

        public BucketAuthDto build() {
            return new BucketAuthDto(id, bucketName, objectId, strategy, authUser, resource, userName);
        }
    }
}
